package com.sxhuayuan.parking.queue.rabbitmq;

import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageBuilder;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.Assert;

import com.sxhuayuan.parking.compenent.RabbitMQConfig;
import com.sxhuayuan.parking.queue.QueueService;
import com.sxhuayuan.parking.queue.msg.QueueMsg;

@Component("rabbitMsgQueue")
public class RabbitMsgQueue implements QueueService {

	@Autowired
	RabbitTemplate rabbitTemplate;

	@Override
	public void push(QueueMsg queueMsg) {
		Assert.notNull(queueMsg, "queueMsg is null");
		Message msg = MessageBuilder.withBody(queueMsg.getBytes()).setHeader("x-delay", 0).build();
		rabbitTemplate.send(RabbitMQConfig.EXCHANGE_DELAY_START, queueMsg.getTopic(), msg);
	}

	@Override
	public void delete(long delayQueueMsgId) {
		// TODO Auto-generated method stub
	}

	@Override
	public void finish(long delayQueueMsgId) {
		// TODO Auto-generated method stub
	}

}
